//
//  SelectModelView.m
//  DriveStudy
//
//  Created by chen on 2017/4/20.
//  Copyright © 2017年 chen. All rights reserved.
//

#import "SelectModelView.h"

@implementation SelectModelView{
    SelectTouch block;
}

-(instancetype)initWithFrame:(CGRect)frame andTouch:(SelectTouch)touch{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
        block = touch;
        _model = testModel;
    }
    return self;
}
-(void)creatUI{
    //透明的视图
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.0];
    //添加两个button
    _arr = @[@"答题模式",@"背题模式"];
    for (int i =0; i<2; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(self.frame.size.width/2 - 50, self.frame.size.height/2 + 130*i -200 , 100, 100);
        btn.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
        [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 60, 60)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d11q.png",i+1]];
        btn.tag = i;
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 10;
        [btn addSubview:imageView];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 75, 80, 20)];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        label.text = _arr[i];
        label.font = [UIFont systemFontOfSize:13];
        [btn addSubview:label];
        
        [self addSubview:btn];
    }
}
-(void)click:(UIButton *)btn{
    switch (btn.tag) {
        case 0:
        {
            _model = testModel;
        }
            break;
        case 1:
        {
            _model = lookingModel;
        }
            break;
        default:
            break;
    }
    block(_model);
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [UIView animateWithDuration:0.5 animations:^{
        self.alpha = 0.0;
    }];
}
@end
